<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="公司名称">
              <a-input placeholder="请输入公司名称" v-model="queryParam.companyName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>

            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

      <a-button type="default" style="margin-left: 10px;" @click="toExamine" >提交审核</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete" />
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down" />
        </a-button>
      </a-dropdown>
      <!--      <a-dropdown v-if="selectedRowKeys.length > 0">-->
      <!--        <a-menu slot="overlay">-->
      <!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>-->
      <!--        </a-menu>-->
      <!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
      <!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        :rowClassName="rowClassName"
        ref="table"
        size="small"
        :scroll="{x:800,y:350}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">


        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>

      </a-table>
    </div>

    <company-data-modal ref="modalForm" @ok="modalFormOk"></company-data-modal>
  </a-card>
</template>

<script>
import { httpAction } from '@api/manage'

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import CompanyDataModal from './modules/CompanyDataModal'

export default {
  name: 'CompanyDataList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    CompanyDataModal
  },
  data() {
    return {
      description: '公司信息数据库管理页面',
      // 表头
      columns: [
        {
          title: '公司名称',
          align: 'left',
          width: 280,
          dataIndex: 'companyName'
        },
        {
          title: '开票信息',
          align: 'left',
          colSpan: 2,
          ellipsis: true,
          width: 300,
          dataIndex: 'billingInfoOne',
          customRender: (value, row, index) => {
            return row.billingInfoOne
          }
        },
        {
          title: '开票数量',
          align: 'center',
          colSpan: 0,
          width: 50,
          dataIndex: 'billingInfoNumber',
          customRender: (value, row, index) => {
            let count = 0
            if (row.billingInfoOne) {
              count = count + 1
            }
            if (row.billingInfoTwo) {
              count = count + 1
            }
            if (row.billingInfoThree) {
              count = count + 1
            }

            return count + '条'

          }
        },
        {
          title: '提交人',
          align: 'center',
          width: 100,
          dataIndex: 'submitter'
        },
        {
          title: '状态',
          dataIndex: 'status',
          align: 'center',
          width: 100,
          defaultValue: '',
          customRender: (text, row) => {
            if (text == 1) {
              return '未提交'
            } else if (text == 3) {
              return '被驳回'
            }
          }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 100,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/companydata/nosubmit',
        delete: '/companydata/delete',
        submit: '/companydata/submit',
        deleteBatch: '/companydata/deleteBatch',
        exportXlsUrl: '/companydata/exportXls',
        importExcelUrl: 'companydata/importExcel'

      },
      dictOptions: {}
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    initDictConfig() {
    },
    toExamine() {
      if (this.selectedRowKeys.length > 0) {
        let param = {
          ids: this.selectedRowKeys
        }
        httpAction(this.url.submit, param, 'post').then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.loadData(1)
          } else {
            this.$message.warning(res.message)
          }
        }).finally(() => {
          // that.confirmLoading = false
        })
      } else {
        this.$message.warning('请选择数据')
      }
    },
    rowClassName(record, index) {
      // console.log(record.status)
      let className = 'light-row'
      if (record.status == 3) className = 'dark-row'
      return className
    },

  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
<style>
.light-row {
  background-color: #fff;
}

.dark-row {
  background-color: #fff1cf;
  color: red;
}
</style>